/**
 * @author		Ben Layet
 * @version 	0.1
 * @date		29 Oct 2008
 * @copyright 	� Canon Europa N. V. 2004
 */
package org.ignoramus.application.view.rcp;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.part.EditorPart;
import org.ignoramus.application.model.Lesson;
import org.ignoramus.application.store.LessonBuilder;
import org.ignoramus.application.store.LessonFile;
import org.ignoramus.application.store.StoreException;

/**
 * 
 */
public class LessonEditor extends EditorPart
{
	private SwtMemoryMap map;
	private Lesson	lesson	= null;

	public void createPartControl(Composite parent)
	{
		parent.setLayout(new RowLayout(SWT.VERTICAL));
		
		if (null == lesson)
		{
			setPartName("No lesson loaded.");
			setContentDescription("No lesson loaded.");
		}
		else
		{
			setPartName(lesson.getTitle());
//			setContentDescription(lesson.getTitle());
			map = new SwtMemoryMap(parent, lesson);
			Button btn = new Button(parent, SWT.CENTER);
			btn.setText("Start Test");
			btn.addSelectionListener(new SelectionListener(){

				@Override
				public void widgetDefaultSelected(SelectionEvent e)
				{
					// TODO Auto-generated method stub
					
				}

				@Override
				public void widgetSelected(SelectionEvent e)
				{
					System.out.println(map.getSelected());
				}});
		}
	}

	public void init(IEditorSite site, IEditorInput input)
	{
		setSite(site);
		setInput(input);

		try
		{
			if (input instanceof FileStoreEditorInput)
			{
				FileStoreEditorInput fileInput = (FileStoreEditorInput) input;
				LessonFile lessonFile = new LessonFile(fileInput.getURI().getPath());
				LessonBuilder lessonBuilder = new LessonBuilder();
				lesson = lessonBuilder.createLesson(lessonFile);
			}

		}
		catch (StoreException e)
		{
			e.printStackTrace();
		}
	}

	public void setFocus()
	{
	}

	/**;
	 * @param monitor
	 */
	@Override
	public void doSave(IProgressMonitor monitor)
	{
		// TODO Auto-generated method stub

	}

	/**
	 * 
	 */
	@Override
	public void doSaveAs()
	{
		// TODO Auto-generated method stub

	}

	/**
	 * @return
	 */
	@Override
	public boolean isDirty()
	{
		// TODO Auto-generated method stub
		return false;
	}

	/**
	 * @return
	 */
	@Override
	public boolean isSaveAsAllowed()
	{
		// TODO Auto-generated method stub
		return false;
	}
}
